#pragma once

#include "RegistryValue.h"
#include <vector>

#include "ViewOptions.h"

static std::wstring GetMyDocumentsDir()
{
    std::vector<wchar_t> myDocPath;
    myDocPath.assign(MAX_PATH + 1, L'\0');

    if (!SHGetSpecialFolderPath(NULL, (LPTSTR)&myDocPath[0], CSIDL_PERSONAL, FALSE))
        return std::wstring();

    return std::wstring((LPTSTR)&myDocPath[0]);
}

static std::wstring GetTempDir()
{
    std::vector<wchar_t> tempPath;
    int sz = ::GetTempPath(0, NULL);
    tempPath.assign(sz, L'\0');

    ::GetTempPath( sz, &tempPath[0] );
    return std::wstring(tempPath.begin(), tempPath.end());
}

class Options : public ViewOptions
{
public:

    Options(const std::wstring& root, HKEY hKey)
        : ViewOptions(root, hKey)
        , workingDir(root + L"WorkingDir", hKey)
        , tempDir(root + L"TempDir", hKey)
        , newInUnicode(root + L"NewInUnicode", hKey)
    {
        if (!workingDir.exists() || WorkingDir().empty()) {
            workingDir = GetMyDocumentsDir() + L"\\Memo\\";
        }

        if (!tempDir.exists() || TempDir().empty()) {
            tempDir = GetTempDir() + L"pmtmp\\";
        }

        if (!newInUnicode.exists()) {
            newInUnicode = false;
        }
    }

    inline std::wstring WorkingDir() { return (std::wstring)workingDir; }
    inline void WorkingDir(const std::wstring& dir) { workingDir = dir; }

    inline std::wstring TempDir() { return (std::wstring)tempDir; }
    inline void TempDir(const std::wstring &dir) { tempDir = dir; }

    bool NewInUnicode() { return (bool)newInUnicode; }

private:
    
    registry_string<std::wstring> workingDir;
    registry_string<std::wstring> tempDir;
    registry_string<bool>         newInUnicode;
};